package com.spzx.channel.service.impl;

import com.spzx.channel.service.IIndexService;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.RemoteProductSkuService;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.SkuQuery;
import com.spzx.product.api.domain.vo.CategoryVo;
import com.spzx.product.api.domain.vo.ProductSkuVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: IndexServiceImpl
 * Package: com.spzx.channel.service.impl
 * Description:
 */
@Service
@Slf4j
public class IndexServiceImpl implements IIndexService {
    @Autowired
    private RemoteCategoryService remoteCategoryService;

    @Autowired
    private RemoteProductSkuService remoteProductSkuService;

    @Override
    public Map<String, Object> getIndexData() {
        HashMap<String, Object> data = new HashMap<>();
        R<List<ProductSku>> productSkuResult = remoteProductSkuService.getTopSale(SecurityConstants.INNER);
        R<List<CategoryVo>> categoryResult = remoteCategoryService.getOneCategory(SecurityConstants.INNER);
        if(R.FAIL==productSkuResult.getCode()){
            log.error("商品服务调用失败:{}",productSkuResult.getMsg());
        }
        if(R.FAIL==categoryResult.getCode()){
            log.error("商品服务调用失败:{}",categoryResult.getMsg());
        }

        data.put("productSkuList",productSkuResult.getData());
        data.put("categoryList",categoryResult.getData());
        return data;
    }

    @Override
    public TableDataInfo getSkuList(Integer pageNum,Integer pageSize,SkuQuery skuQuery) {
        TableDataInfo productSkuList = remoteProductSkuService
                .getProductSkuList(pageNum,pageSize,SecurityConstants.INNER, skuQuery);
        if (R.FAIL == productSkuList.getCode()){
            log.error("调用商品服务失败:{}",productSkuList.getMsg());
        }
        return productSkuList;
    }
}
